home *** CD-ROM | disk | FTP | other *** search
/ PC Home 138 / PC Home issue 138.iso / Software / Essentials / Netscape / nim.xpi / bin / chrome / aim.jar / content / aim / BuddyAddBuddy.js < prev    next >
Encoding:
Text File  |  2001-09-18  |  2.5 KB  |  100 lines

  1. var RDF = aimRDF();
  2. var aim = aimRDFDataSource();
  3. var containerClass = Components.classes['@mozilla.org/rdf/container;1'];
  4. var container = containerClass.createInstance(Components.interfaces.nsIRDFContainer);
  5. container.Init(aim, RDF.GetResource("NC:AIM/BuddyList"));
  6.  
  7. function BuildGroupFrame(groupName)    
  8. {
  9.     var a = new Array();
  10.     var i = 0;
  11.     top.a = a;
  12.  
  13.     var enumerator = container.GetElements();
  14.  
  15.     while (enumerator.hasMoreElements()) {
  16.  
  17.         var element = enumerator.getNext();
  18.         var resource = element.QueryInterface(Components.interfaces.nsIRDFResource);
  19.         dump( "Element is " + element + "\n" );
  20.         dump( "Resource is " + resource + "\n" );
  21.         var attr = aim.GetTarget(resource, 
  22.             RDF.GetResource("http://home.netscape.com/NC-rdf#Name"), true);
  23.         if (attr)
  24.             attr = attr.QueryInterface(Components.interfaces.nsIRDFLiteral);
  25.         if (attr) {
  26.             attr = attr.Value;
  27.             a[ i ] = attr;
  28.             i = i + 1;
  29.         }
  30.     }
  31.     CreateGroupList( a, groupName );
  32. }
  33.  
  34. function CreateGroupList( a, groupName )
  35. {
  36.  
  37.  
  38.     listDocument = document.getElementById("AddBuddyGroupList")
  39.     
  40.     listDocument.appendChild(document.createElement("spacer"))
  41.     
  42.     for ( var i=0; i < a.length; i++ ) {
  43.         chkboxname = "checkBox" + a[i];
  44.         outputElement = document.createElement('checkbox')
  45.         outputElement.setAttribute('id',chkboxname)
  46.         outputElement.setAttribute('name',a[i])
  47.         outputElement.setAttribute('label',a[i])
  48.         if (groupName) {
  49.         for (var j=0; j<groupName.length; j++) {
  50.              if (a[i] == groupName[j]) {
  51.                  outputElement.setAttribute("checked", "true")
  52.              }
  53.         }
  54.          }
  55.         listDocument.appendChild(outputElement)    
  56.         //dump("docwriting!"+ outputElement +"\n" );
  57.     }
  58.     listDocument.appendChild(document.createElement("spacer"))
  59.  
  60. }
  61.  
  62. function GetCheckBoxState( a, i )
  63. {
  64.     chkboxname = "checkBox" + a[i];
  65.     chkbox = document.getElementById(chkboxname);
  66.     return( chkbox.checked );
  67. }
  68.  
  69. // for later 
  70.  
  71. function FindSelectedGroup()
  72. {
  73.     // Locate selection in setup list
  74.     // XXX There must be a better way to do this
  75.  
  76.     var selectedGroup = null;
  77.     var tree = window.tree;
  78.     var groups = tree.childNodes[2].childNodes;
  79.  
  80.     for (var i = 0; i != groups.length; i++) {
  81.         if (groups[i].getAttribute("selected") == "true") {
  82.             selectedGroup = groups[i].getAttribute("Name");
  83.             break;
  84.         }
  85.     }
  86.     return( selectedGroup );
  87. }
  88.  
  89. function FindBuddySelected( group, tree )
  90. {
  91.     var buddyList;
  92.     
  93.     if ( tree )
  94.         buddyList = tree.selectedItems;
  95.  
  96.     if ( !buddyList || buddyList.length != 1 )
  97.         return null;
  98.     return( buddyList[0].getAttribute("Name") );
  99. }
  100.